"""Extra functions added to the Jinja template context."""

from hcp.jinja import jinja_global
from django.conf import settings

@jinja_global
def url(view_name, *args, **kwargs):
    from django.core.urlresolvers import reverse, NoReverseMatch
    url = ''
    try:
        url = reverse(view_name, args=args, kwargs=kwargs)
    except NoReverseMatch:
        project_name = settings.SETTINGS_MODULE.split('.')[0]
        url = reverse(project_name + '.' + view_name,
                      args=args, kwargs=kwargs)
    return url
